package tests;


import gameComponents.Player;
import gamePieces.Knight;

import java.awt.Point;
import java.util.ArrayList;

import junit.framework.TestCase;

/**
 * 
 */

/**
 * @author SELMAN
 *
 */
public class KnightTest extends TestCase {
	
	Player p = new Player(1);
	Knight n = new Knight(0, 0, p); //initializes a knight at (0,0)

	/**
	 * @param name
	 */
	public KnightTest(String name) {
		super(name);
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
	}

	/**
	 * Test method for {@link Knight#checkIfLegal(int, int)}.
	 * @author Selman Selman
	 */
	public final void testCheckIfLegal() {
		//check if checkIfLegal would return true if Knight moved in L shape
		assertTrue(n.checkIfLegal(1,2));
		//check if checkIfLegal would return false if Knight did not move in L shape
		assertFalse(n.checkIfLegal(1, 3));
		//check if checkIfLegal would return false if Knight was trying to move out of boundaries
		assertFalse(n.checkIfLegal(9, 10));
	}

	/**
	 * Test method for {@link Piece#getX()}.
	 * @author Selman Selman
	 */
	public final void testGetX() {
		//since knight is created initially at (0,0)
		//getX() should return 0
		assertEquals(n.getX(),0);
	}

	/**
	 * Test method for {@link Piece#getY()}.
	 * @author Selman Selman
	 */
	public final void testGetY() {
		//since knight is created initially at (0,0)
		//getY() should return 0
		assertEquals(n.getY(),0);
	}

	/**
	 * Test method for {@link Piece#setX(int)}.
	 * @author Selman Selman
	 */
	public final void testSetX() {
		n.setX(1); // set x coordinate to 1
		//check that x is now 1
		assertEquals(n.getX(),1);
	}

	/**
	 * Test method for {@link Piece#getOwnership()}.
	 * @author Selman Selman
	 */
	public final void testGetOwnership() {
		//get Ownership should return object p
		assertEquals(n.getOwnership(),p);
	}

	/**
	 * Test method for {@link Piece#setY(int)}.
	 * @author Selman Selman
	 */
	public final void testSetY() {
		n.setY(1); // set y coordinate to 1
		//check that y is now 1
		assertEquals(n.getY(),1);
	}

	/**
	 * Test method for {@link Piece#getMoves()}.
	 * @author Selman Selman
	 */
	public final void testGetMoves() {
		n.possibleMoves();//calculate possible moves of knight at (0,0)
		//possible moves should be (1,2) or (2,1)
		ArrayList<Point> p = n.getMoves(); //get the possible moves
		assertTrue(p.contains(new Point(1,2))); //check if (1,2) is in possible moves
		assertTrue(p.contains(new Point(2,1)));//check if (2,1) is in possible moves
		//makes sure it does not contain a wrong possible move
		assertFalse(p.contains(new Point(3,3)));
	}

	/**
	 * Test method for {@link Knight#move(int, int)}.
	 * @author Selman Selman
	 */
	public final void testMove() {
		//checks if knight will move in an L shape
		n.move(1,2);
		assertEquals(n.getX(),1);
		assertEquals(n.getY(), 2);
		//new x and y coordinates are 1 and 2 respectively 
		//check if knight will not move in any other shape than L
		n.move(1,3); //knight should not move
		assertEquals(n.getX(),1);
		assertEquals(n.getY(),2);
		//move knight out of boundaries
		n.move(9,10); //knight should not move
		assertEquals(n.getX(),1);
		assertEquals(n.getY(),2);
	}

}
